package keye.document_manage.interceptor;

import java.util.Properties;

import org.apache.ibatis.plugin.Interceptor;
import org.apache.ibatis.plugin.Intercepts;
import org.apache.ibatis.plugin.Invocation;
import org.apache.ibatis.plugin.Plugin;
import org.apache.ibatis.plugin.Signature;
import org.apache.ibatis.reflection.MetaObject;
import org.apache.ibatis.reflection.SystemMetaObject;
import org.apache.ibatis.session.ResultContext;
import org.apache.ibatis.session.ResultHandler;

/**
 * 查询两个属性是，映射为map，一个作为key，一个作为value
 *
 */
@Intercepts({@Signature(type=ResultHandler.class,method="handleResult",args={ResultContext.class})})
public class ResultMapInterceptor implements Interceptor{

	@Override
	public Object intercept(Invocation invocation) throws Throwable {
		ResultHandler<?> resultHandler = (ResultHandler<?>) invocation.getTarget();
		@SuppressWarnings("unused")
		MetaObject metaObject = SystemMetaObject.forObject(resultHandler);
		return invocation.proceed();
	}

	@Override
	public Object plugin(Object target) {
		if (target instanceof ResultHandler) {  
			System.out.println("PageInterceptor.plugin(Object target)");
	        return Plugin.wrap(target, this);  
	    } else {  
	        return target;  
	    } 
	}

	@Override
	public void setProperties(Properties properties) {
		// TODO Auto-generated method stub
		
	}

}
